window.onload=function(){
    init()
}
function init(){
    Array.from(document.getElementsByClassName('app_item')).forEach(appItem=>{
        appItem.addEventListener('click',function(){
            document.getElementById('main').classList.add('info_visible')
            getAppInfo(appItem.textContent)
        })
    })
    Array.from(document.getElementsByClassName('tab_item')).forEach(tabEL=>{
        tabEL.addEventListener('click',function(){changeTab(tabEL)})
    })
}
function closeAppInfoFrame(){
    document.getElementById('main').classList.remove('info_visible')
}
function changeTab(tabEL){
    document.getElementsByClassName('tab_item')[0].classList.remove('tab_active')
    document.getElementsByClassName('tab_item')[1].classList.remove('tab_active')
    tabEL.classList.toggle('tab_active')
    if(tabEL.textContent=='应用信息'){
        document.getElementById('app_info').classList.remove('tab_changed')
    }else{
        document.getElementById('app_info').classList.add('tab_changed')
    }
}
function getAppInfo(appName){
    fetch('/app_info?app_name='+appName,{method:'GET'}).then(resp=>{
        if(resp.status!=200){
            alert('获取APP信息失败')
            return
        }
        resp.json().then(data=>{
            settingAppInfo(data)
        })
    }).catch(err=>{
        alert('获取APP信息失败'+err)
    })
}
function settingAppInfo(appInfoData){
    vue.$data.appName=appInfoData.appName
    vue.$data.appLogo=appInfoData.appLogo
    vue.$data.appDesc=appInfoData.appDesc
    vue.$data.appSize=Math.round(appInfoData.appSize/1024.0)
    vue.$data.appFile=appInfoData.appFile
    vue.$data.appFrom=appInfoData.appFrom
    vue.$data.appShot=appInfoData.appShot.split(';').filter(img=>img!='')
    vue.$data.appCategory=appInfoData.appCategory
}
function getAppList(category){
    if(category=='全部')return
}
let vue=new Vue({
    el:'#app_info',
    data:{
        appName:"",
        appLogo:"",
        appDesc:"",
        appSize:"",
        appFile:"",
        appFrom:"",
        appShot:"".split(';'),
        appCategory:""
    },mounted:function (){

    }
    ,methods:{

    }
})